namespace NCT.INVPOS.DataAccessLayer.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class initial_create : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Products",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 30),
                        Description = c.String(maxLength: 100),
                        Code = c.String(nullable: false, maxLength: 30),
                        Model = c.String(maxLength: 30),
                        ManufacturerId = c.Int(),
                        CategoryId = c.Int(),
                        ListPrice = c.Double(nullable: false, defaultValue:0.00),
                        SalesPrice = c.Double(nullable: false, defaultValue: 0.00),
                        Discount1 = c.Double(nullable: false, defaultValue: 0.00),
                        Discount2 = c.Double(nullable: false, defaultValue: 0.00),
                        Discount3 = c.Double(nullable: false, defaultValue: 0.00),
                        Discount4 = c.Double(nullable: false, defaultValue: 0.00),
                        Discount5 = c.Double(nullable: false, defaultValue: 0.00),
                        Cost = c.Double(nullable: false, defaultValue: 0.00),
                        QtyOnHand = c.Int(nullable: false, defaultValue: 0),
                        ExtendedCost = c.Double(nullable: false, defaultValue: 0.00),
                        SupplierId = c.Int(),
                        IsTaxable = c.Boolean(nullable: false),
                        BranchId = c.Int(),
                        IsActive = c.Boolean(nullable: false, defaultValue:true),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Manufacturers", t => t.ManufacturerId)
                .ForeignKey("dbo.Categories", t => t.CategoryId)
                .ForeignKey("dbo.Suppliers", t => t.SupplierId)
                .ForeignKey("dbo.Branches", t => t.BranchId)
                .Index(t => t.ManufacturerId)
                .Index(t => t.CategoryId)
                .Index(t => t.SupplierId)
                .Index(t => t.BranchId);
            
            CreateTable(
                "dbo.Manufacturers",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 30),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 30),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Suppliers",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Code = c.String(maxLength: 30),
                        FirstName = c.String(maxLength: 30),
                        MiddleName = c.String(maxLength: 30),
                        LastName = c.String(nullable: false, maxLength: 30),
                        Phone = c.String(maxLength: 4000),
                        ContactExt = c.String(maxLength: 5),
                        Contact = c.String(maxLength: 30),
                        Fax = c.String(maxLength: 20),
                        Email = c.String(maxLength: 40),
                        Address = c.String(maxLength: 100),
                        IsActive = c.Boolean(nullable: false, defaultValue:true),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Branches",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 30),
                        IsActive = c.Boolean(nullable: false, defaultValue:true),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Customers",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        FirstName = c.String(nullable: false, maxLength: 30),
                        LastName = c.String(nullable: false, maxLength: 30),
                        MiddleName = c.String(maxLength: 30),
                        BillingAddress = c.String(maxLength: 100),
                        ShippingAddress = c.String(maxLength: 100),
                        Gender = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.Products", new[] { "BranchId" });
            DropIndex("dbo.Products", new[] { "SupplierId" });
            DropIndex("dbo.Products", new[] { "CategoryId" });
            DropIndex("dbo.Products", new[] { "ManufacturerId" });
            DropForeignKey("dbo.Products", "BranchId", "dbo.Branches");
            DropForeignKey("dbo.Products", "SupplierId", "dbo.Suppliers");
            DropForeignKey("dbo.Products", "CategoryId", "dbo.Categories");
            DropForeignKey("dbo.Products", "ManufacturerId", "dbo.Manufacturers");
            DropTable("dbo.Customers");
            DropTable("dbo.Branches");
            DropTable("dbo.Suppliers");
            DropTable("dbo.Categories");
            DropTable("dbo.Manufacturers");
            DropTable("dbo.Products");
        }
    }
}
